package com.by.controller;

import com.by.biz.AdminBiz;
import com.by.biz.TbBiz;
import com.by.dao.TbDao;
import com.by.entity.Admin;
import com.by.entity.Tb;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
@Controller
public class TbController {
    @Autowired
    private TbBiz tbBiz;
    @Autowired
    private AdminBiz adminBiz;


    @RequestMapping("/login")
//    @ResponseBody
    public String queryTb(Admin admin,Model model){
        Admin admin1 = adminBiz.adminLogin(admin);
        List<Tb> tbs = tbBiz.queryTbList();
        model.addAttribute("tbs",tbs);
        model.addAttribute("admin1",admin1);
        if (admin1!=null){
            return "tbs";
        }else{
            return "/loginpage.html";
        }
    }

    @RequestMapping("/reg")
    public String addAdmin(Admin admin,Model model){
        int sign = adminBiz.addAdmin(admin);
        model.addAttribute("sign",sign);
        if (sign>0){
            return "/loginpage.html";
        }else {
            return "/sign.html";
        }
    }

    /*@RequestMapping("/addTb")
    public int addTb(Tb tb, Model model){
        int t = tbBiz.addTb(new Tb(69,"关羽","语文","106",3));
        model.addAttribute("t",t);
        System.out.println(t);
        return t;
    }


    @RequestMapping("/delTb")
    public void delTb(){
        int id = 32;
        tbBiz.delTb(id);
    }

    @RequestMapping("/updateTb")
    public int update(Tb tb,Model model){
        int t = tbBiz.update(new Tb(69,"张飞","英语","108",2));
        return t;
    }*/
}
